<template>
<el-dialog
    :title="$t('plus.order_price_edit')"
    v-model="dialogVisible"
    @close="dialogFormVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="30%"
  >
    <el-form size="small" :model="order" ref="order">
      <el-form-item
        :label="$t('plus.order_amount')"
        :label-width="formLabelWidth"
        prop="update_price"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input
          type="number"
          v-model="order.update_price"
          autocomplete="off"
        ></el-input>
        <p>{{$t('plus.final_payment_formula')}}</p>
      </el-form-item>
      <el-form-item
        :label="$t('plus.shipping_fee')"
        :label-width="formLabelWidth"
        prop="update_express_price"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input
          type="number"
          v-model="order.update_express_price"
          autocomplete="off"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible">{{$t('plus.cancel')}}</el-button>
        <el-button type="primary" @click="submitFunc()" :loading="loading"
          >{{$t('plus.confirm')}}</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>

<script>
import OrderApi from "@/api/order.js";
export default {
  data() {
    return {
      orderId: 0,
      loading: false,
      /*左边长度*/
      formLabelWidth: "100px",
      /*是否显示*/
      dialogVisible: true,
      /*表单*/
      order: {
        update_price: 0,
        update_express_price: 0.0
      }
    };
  },
  props: ["open_edit"],
  created() {
    this.orderId = this.$route.query.orderId;
    this.getData();
  },
  methods: {
    //            获取数据
    getData() {
      let self = this;
      OrderApi.orderdetail({
        orderId: this.orderId
      }, true).then(data => {
        self.loading = false;
        self.order.update_price = data.data.detail.pay_price;
      }).catch(error => {
        self.loading = false;
      });
    },
    /*确认事件*/
    submitFunc(e) {
      let self = this;
      let order = this.order;
      self.$refs.order.validate(valid => {
        if (valid) {
          self.loading = true;
          OrderApi.updatePrice({
            orderId: this.orderId,
            order: order
          }, true).then(data => {
            self.loading = false;
            ElMessage({
              message: $t("plus.edit_success2"),
              type: "success"
            });
            self.dialogFormVisible(true);
          }).catch(error => {
            self.loading = false;
          });
        }
      });
    },
    /*关闭弹窗*/
    dialogFormVisible() {
      this.$emit("close", {
        openDialog: false
      });
    }
  }
};
</script>

